home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16101 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  66 lines

  1. Newsgroups: comp.lang.c++
  2. Path: artemis.sto.fdata.se!news
  3. From: Niklas Mellin <niklas.mellin@sto.fdata.se>
  4. Subject: Re: What are the differences between structures and classes in C++ ?
  5. Sender: news@artemis.sto.fdata.se (UseNet NetNews)
  6. Message-ID: <316A7639.3383@sto.fdata.se>
  7. Date: Tue, 9 Apr 1996 14:37:45 GMT
  8. Content-Transfer-Encoding: 7bit
  9. Content-Type: text/plain; charset=us-ascii
  10. References: <4k5m65$av@hpscit.sc.hp.com>
  11. Mime-Version: 1.0
  12. X-Mailer: Mozilla 2.0 (WinNT; I)
  13. Organization: WM-data F÷rsvarsdata AB, Sweden
  14.  
  15. Raghuveera Ravinutala wrote:
  16. > Hi,
  17. >      Please mail me the differences between structures and classes in C++.
  18. > Raghu.
  19.  
  20. This is an interesting thread. I have so far read 11 answers to the original
  21. question, and nobody came up with the correct answer, even though it is in
  22. the FAQ:
  23.  
  24. |Q130: What's the difference between the keywords struct and class?
  25. |
  26. |The members and base classes of a struct are public by default, while in class,
  27.              ^^^^^^^^^^^^^^^^
  28. |they default to private.  Note: you should make your base classes EXPLICITLY
  29. |public, private, or protected, rather than relying on the defaults.
  30. |
  31. |"struct" and "class" are otherwise functionally equivalent.
  32.  
  33. This means that:
  34.  
  35. class X: BaseX
  36. {
  37.   int x;
  38. };
  39.  
  40. is equivalent to:
  41.  
  42. struct X: private BaseX
  43. {
  44. private:
  45.   int x;
  46. };
  47.  
  48. and that:
  49. struct Y: BaseY
  50. {
  51.   int y;
  52. };
  53.  
  54. is equivalent to:
  55. class Y: public BaseY
  56. {
  57. public:
  58.   int y;
  59. };
  60.  
  61. ---
  62. Niklas Mellin
  63.  
  64. PS. The FAQ can be found at: ftp://rtfm.mit.edu/pub/usenet/comp.lang.c++
  65.